package com.zlm.user.emp.controller;

import com.zlm.common.base.BaseController;
import com.zlm.common.dto.JsonResultDto;
import com.zlm.common.dto.userEmp.EmpPunchDto;
import com.zlm.common.dto.userEmp.EmpPunchParamsDto;
import com.zlm.common.dto.userEmp.EmpPunchResponseDto;
import com.zlm.user.emp.service.EmpPunchService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

/**
 * 考勤控制类
 * @Author: duyufu
 * @Date: 2019/5/28 11:44
 */
@RestController
@RequestMapping("/empPunch")
public class EmpPunchController extends BaseController {
    @Autowired
    private EmpPunchService empPunchService;

    /**
     * 获取指定日期考勤
     * @param empId
     * @param punchDate
     * @param workTimeId
     * @return
     */
    @GetMapping("/queryEmpPunch")
    public JsonResultDto queryEmpPunch(Integer empId, String punchDate, Integer workTimeId) {
        try {
            EmpPunchResponseDto responseDto = empPunchService.queryEmpPunch(empId,punchDate,workTimeId);
            return success(responseDto);
        } catch (Exception e) {
            e.printStackTrace();
            return fail(e.getMessage());
        }
    }

    /**
     * 获取指定日期考勤部分信息
     * @param empId
     * @param punchDate
     * @return
     */
    @GetMapping("/queryEmpPunchDay")
    public JsonResultDto queryEmpPunchDay(String empId, String punchDate) {
        try {
            List<Map<String,Object>> punchDayList = empPunchService.queryEmpPunchDay(empId,punchDate);
            return success(punchDayList);
        } catch (Exception e) {
            e.printStackTrace();
            return fail(e.getMessage());
        }
    }

    /**
     * 考勤统计
     * @param empId
     * @param date
     * @return
     */
    @GetMapping("/countPunch")
    public JsonResultDto countPunch(Integer empId, String date) {
        try {
            EmpPunchDto empPunchDto = empPunchService.countEmpPunch(empId,date);
            return success(empPunchDto);
        } catch (Exception e) {
            e.printStackTrace();
            return fail(e.getMessage());
        }
    }

    /**
     * 考勤详情
     * @param empId
     * @param date
     * @return
     */
    @GetMapping("/punchDetail")
    public JsonResultDto punchDetail(Integer empId, String date) {
        try {
            List<Map<String,Object>> punchDetailList = empPunchService.punchDetail(empId,date);
            return success(punchDetailList);
        } catch (Exception e) {
            e.printStackTrace();
            return fail(e.getMessage());
        }
    }

    /**
     * 员工考勤打卡
     * @param empPunchParamsDto
     * @return
     */
    @PostMapping("/empPunch")
    public JsonResultDto empPunch(@RequestBody EmpPunchParamsDto empPunchParamsDto) {
        try {
            empPunchService.empPunch(empPunchParamsDto);
            return success();
        } catch (Exception e) {
            e.printStackTrace();
            return fail(e.getMessage());
        }
    }

}
